package sd.qd.xiaoming.coffeedesk.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;

import sd.qd.xiaoming.coffeedesk.entity.CdDict;

@Repository
public class DictionaryDAO {
    
    @PersistenceContext
    private EntityManager entityManager;
    
    @SuppressWarnings("unchecked")
    public List<CdDict> getAll() {
        return this.entityManager.createQuery("select d from Dictionary d")
                .getResultList();
    }
    
    public CdDict getByCode(final String code) {
        Query query = this.entityManager.createQuery(
                "select d from CdDict d where d.code=:code");
        query.setParameter("code", code);
        return (CdDict) query.getSingleResult();
    }
    
}
